/*
 *  ME218_Sprites.c
 *  ArduinoOnXcode
 *
 *  Created by Rick Miley on 3/17/11.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */



#include <ME218_Sprites.h>




// ======================= initializeSPRITEs ======================

void initializeSPRITEs() {
	int i;
	ALL_GRAPHIC_SPRITE_ARRAY*	TT_ALL_SPRITE;
	SINGLE_SPRITE_ARRAY*		TT_SINGLE_SPRITE;
	int temp_TT_total_cnt, temp_TT_sx,temp_TT_sy,temp_TT_hs,temp_TT_vs;
	int	temp_TT_visible,temp_TT_rotation;
	unsigned long temp_SS_dly;
	prog_uchar *temp_SS_raw;
	
	
	/// global variables used in the interrupt handler
	live_SPRITE = 0;
	sprite_smile=0;
	
	
	
	TT_ALL_SPRITE=(ALL_GRAPHIC_SPRITE_ARRAY *)SUPER_MAGIC_SPRITE_VARIABLE;
	
	
	// TIP_TOP_Total is FighterA,FighterB,&FighterC
	for (i=0;i<TIP_TOP_TOTAL;i++) {
		TT_SINGLE_SPRITE=(SINGLE_SPRITE_ARRAY *)pgm_read_word_near(&TT_ALL_SPRITE[i].init_TIPTOP_SPRITE_frames_array);
		temp_TT_sx=pgm_read_word_near(&TT_ALL_SPRITE[i].init_TIPTOP_SPRITE_starting_x);
		temp_TT_sy=pgm_read_word_near(&TT_ALL_SPRITE[i].init_TIPTOP_SPRITE_starting_y);
	    temp_TT_vs=pgm_read_word_near(&TT_ALL_SPRITE[i].init_TIPTOP_SPRITE_vertical_size);
		temp_TT_hs=pgm_read_word_near(&TT_ALL_SPRITE[i].init_TIPTOP_SPRITE_horizontal_size);
		temp_TT_total_cnt=pgm_read_word_near(&TT_ALL_SPRITE[i].init_TIPTOP_SPRITE_num_stages);
		temp_TT_visible=pgm_read_word_near(&TT_ALL_SPRITE[i].init_TIPTOP_SPRITE_visible);
		temp_TT_rotation=pgm_read_word_near(&TT_ALL_SPRITE[i].init_TIPTOP_SPRITE_rotation);
		
		
		temp_SS_dly=(prog_uint16_t)pgm_read_word_near(&TT_SINGLE_SPRITE->starting_SPRITE_delay);
		temp_SS_raw=(prog_uchar *)pgm_read_word_near(&TT_SINGLE_SPRITE->GRAPHIC_SPRITE_raw_data); 
		
		if(temp_TT_rotation)
			SpriteTable[i].ls_index=0;
		else
			SpriteTable[i].ls_index=temp_TT_total_cnt-1;
		
		SpriteTable[i].ls_total_cnt=temp_TT_total_cnt;
		SpriteTable[i].ls_delay=temp_SS_dly;			
		
		
		SpriteTable[i].ls_horizontal_size=temp_TT_hs;
		SpriteTable[i].ls_vertical_size=temp_TT_vs;
		
		SpriteTable[i].ls_visible=temp_TT_visible;
		SpriteTable[i].ls_rotation=temp_TT_rotation;
		
		
		SpriteTable[i].ls_speed_numerator=100;			// speed is computed by 
		// numerator divided by denominator
		SpriteTable[i].ls_speed_denominator=100;		// multiplied by delay
		
		SpriteTable[i].ls_current_x=temp_TT_sx;		// set the starting position
		SpriteTable[i].ls_current_y=temp_TT_sy;
		
		
	}
	
	
}




